/*
ID: quxiao82
LANG: C++
PROG: msquare
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <set>
using namespace std;

const int NUM = 8;
const int MAX = 50000;

struct Config
{
     int seq[NUM];
     int lastOp;          //0 A, 1 B, 2 C
     int lastIdx;
};

Config initConfig, desConfig;
Config configs[MAX];
int head, tail;
//short int visited[16780489];
//vector<int> visited;
set<int> visited;
vector<char> ans;

// bool stateVisited (int state)
// {
//      int i;
//      for(i = 0; i < visited.size(); i ++)
//      {
//           if ( visited[i] == state )
//                return true;
//      }
//      return false;
// }

void Input ()
{
     int i;
     for (i = 0; i < NUM; i ++)
          scanf("%d", &desConfig.seq[i]);
}

int getState (Config config)
{
     int i, state = 0;
     for (i = 0; i < NUM; i ++)
     {
          state = state*8 + (config.seq[i]-1);
     }
     return state;
}

Config OpA (Config config)
{
     swap(config.seq[0], config.seq[7]);
     swap(config.seq[1], config.seq[6]);
     swap(config.seq[2], config.seq[5]);
     swap(config.seq[3], config.seq[4]);
     config.lastOp = 0;
     return config;
}

Config OpB (Config config)
{
     int tmp;
     tmp = config.seq[0];
     config.seq[0] = config.seq[3];
     config.seq[3] = config.seq[2];
     config.seq[2] = config.seq[1];
     config.seq[1] = tmp;
     tmp = config.seq[7];
     config.seq[7] = config.seq[4];
     config.seq[4] = config.seq[5];
     config.seq[5] = config.seq[6];
     config.seq[6] = tmp;
     config.lastOp = 1;
     return config;
}

Config OpC (Config config)
{
     int tmp;
     tmp = config.seq[1];
     config.seq[1] = config.seq[6];
     config.seq[6] = config.seq[5];
     config.seq[5] = config.seq[2];
     config.seq[2] = tmp;
     config.lastOp = 2;
     return config;
}

void OutputAns (int idx)
{
//      if ( idx == 0 )
//           return;
//      FindPath(configs[idx].lastIdx);
//      ans.push_back('A'+configs[idx].lastOp);
     while ( idx )
     {
          ans.push_back('A'+configs[idx].lastOp);
          idx = configs[idx].lastIdx;
     }
     int i, l, tmp;
     l = ans.size();
     printf("%d\n", l);
     for (i = l-1; i >= 0; i --)
     {
          putchar(ans[i]);
          tmp = l - i - 1;
          if ( tmp && tmp % 60 == 0 )
               putchar('\n');
     }
     if ( l == 0 || l % 60 != 0 )
          putchar('\n');
}

// void OutputAns()
// {
//      int i, l;
//      l = ans.size();
//      printf("%d", l);
//      for (i = 0; i < l; i ++)
//      {
//           if ( i % 60 == 0 )
//                putchar('\n');
//           putchar(ans[i]);
//      }
//      putchar('\n');
// }

void Solve ()
{
     int i, state, finalState;
     Config c1, c2;
     for (i = 0; i < NUM; i ++)
          initConfig.seq[i] = i + 1;
     initConfig.lastIdx = initConfig.lastOp = -1;
     finalState = getState(desConfig);

     head = tail = 0;
     configs[tail++] = initConfig;
     //visited.push_back( getState(initConfig) );
     visited.insert( getState(initConfig) );
     while ( head != tail )
     {
          c1 = configs[head];
          if ( getState(c1) == finalState )
          {
               OutputAns(head);
               return;
          }
          c2 = OpA(c1);
          c2.lastIdx = head;
          state = getState(c2);
          /*if ( !stateVisited(state) )*/
          if ( visited.find(state) == visited.end() )
          {
               //visited.push_back(state);
               visited.insert(state);
               configs[tail++] = c2;
          }
          c2 = OpB(c1);
          c2.lastIdx = head;
          state = getState(c2);
          /*if ( !stateVisited(state) )*/
          if ( visited.find(state) == visited.end() )
          {
               //visited.push_back(state);
               visited.insert(state);
               configs[tail++] = c2;
          }
          c2 = OpC(c1);
          c2.lastIdx = head;
          state = getState(c2);
          /*if ( !stateVisited(state) )*/
          if ( visited.find(state) == visited.end() )
          {
               //visited.push_back(state);
               visited.insert(state);
               configs[tail++] = c2;
          }
          head ++;
//          printf("tail %d\n", tail);
     }
}

int main ()
{
     freopen("msquare.in", "r", stdin);
     freopen("msquare.out", "w", stdout);

     Input ();
     Solve ();

     return 0;
}